function azimuth_intercepts = fix_close_targets(azimuth_intercepts, radar_beam_width)

[num_radars, num_targets] = size(azimuth_intercepts);

allowed_sign = zeros(1, num_radars);

for radar = 1:num_radars
  target2 = 0;
  allowed_sign(radar) = sign(azimuth_intercepts(radar, end) - azimuth_intercepts(radar, 1));
  
  for target = 3:num_targets-1
    if (target <= target2)
      continue
    end
    
    delta = azimuth_intercepts(radar, target)-azimuth_intercepts(radar, target-1);
    delta_sign = sign(delta);
    if (abs(delta) < radar_beam_width(radar)) && (delta_sign ~= allowed_sign(radar))
      min_az = azimuth_intercepts(radar, target-1);
      max_az = azimuth_intercepts(radar, target-1);
      next_target = target;
      
      for target2 = next_target:num_targets-1
        delta_max = azimuth_intercepts(radar, target2) - min_az;
        sign_max = sign(delta_max);
        delta_min = azimuth_intercepts(radar, target2) - max_az;
        sign_min = sign(delta_min);
        
        if (abs(delta_max) >= radar_beam_width(radar)) || (sign_max == allowed_sign(radar)) ...
        || (abs(delta_min) >= radar_beam_width(radar)) || (sign_min == allowed_sign(radar))
          break;
        end
        
        if (azimuth_intercepts(radar, target2) < min_az)
          min_az = azimuth_intercepts(radar, target2);
        elseif (azimuth_intercepts(radar, target2) > max_az)
          max_az = azimuth_intercepts(radar, target2);
        end
      end
      
      if (abs(delta_max) < radar_beam_width(radar)) && (sign_max ~= allowed_sign(radar)) ...
      && (abs(delta_min) < radar_beam_width(radar)) && (sign_min ~= allowed_sign(radar))
        for t=target-1:target2
          azimuth_intercepts(radar, t) = (max_az + min_az) / 2;
        end
      else
        for t=target-1:target2-1
          azimuth_intercepts(radar, t) = (max_az + min_az) / 2;
        end
      end
    end
  end
end

end